const wxHttpHandler = require('../../utils/wxHttpHandler.js');
const api = require('../../APIConfig/apiConfig.js');
var app = getApp();

Page({

  data: {
    freezerList: [], //冷库列表
    unitsList: [], //设备

  },

  onLoad: function (options) {
    this.getColdlist()
  },
  onShow: function () {

  },

  freezerTap: function (e) {
    this.getColdDetails(e.currentTarget.dataset.a)
    wx.setNavigationBarTitle({
      title: e.currentTarget.dataset.b,
    })
  },

  //获取冷库列表
  getColdlist: function () {
    wx.showLoading()
    let data = {}
    const that = this
    wxHttpHandler({
      type: 'post',
      path: api.getColdlist,
      data: data,
      fn: function (res) {
        wx.hideLoading()
        if (res.code == 0) {
          that.setData({
            freezerList: res.data
          })
          if (that.data.freezerList.length > 0) {
            that.getColdDetails(that.data.freezerList[0].id)
            wx.setNavigationBarTitle({
              title: that.data.freezerList[0].name,
            })
          }
        } else {
          wx.showToast({
            title: res.desc,
            icon: 'none',
            duration: 1500,
            mask: true
          });
        }
      }

    })
  },

  //获取冷库详情
  getColdDetails: function (e) {
    wx.showLoading()
    let data = {}
    const that = this
    wxHttpHandler({
      type: 'get',
      path: api.getColdDetails + e,
      data: data,
      fn: function (res) {
        wx.hideLoading()
        if (res.code == 0) {
          that.setData({
            unitsList: res.data
          })
        } else {
          wx.showToast({
            title: res.desc,
            icon: 'none',
            duration: 1500,
            mask: true
          });
        }
      }

    })
  },


})